Rule lookup as a trie - #232
Draft
webdevred wants to merge 10 commits into
Draft
Conversation
The rule lookup is about to become a trie, and nothing pinned the two things that change would have to preserve: that a pattern matches only once consumed whole, with leftover breadcrumbs allowed under PrefixMatch alone, and which of the two modes each property is read in. Moving AutoPad across left every fixture green.
`.test*` is documented JBFL and shipped, so the trie has to solve it rather than decide whether to keep it. It is also the one selector that cannot be keyed on directly, since the stored key is a prefix of the breadcrumb rather than the same text.
Precedence was whatever fell out of Ord NodePattern, and part of it was plainly wrong: against the key deformGroups the pattern .de* beat .deform*, so the less specific rule won. The rule is now specificity, meaning how many nodes a selector can match, and these specs state it. Two of them fail until rank stops delegating to the derived Ord on NodeSelector. Also pinned: a less specific pattern still supplies properties the winner does not set. Every shipped ruleset depends on it, since .* carries Indent and TrailingComma for the whole file.
`[4]` is the last row of the selector table that no shipped ruleset uses, so nothing else would notice it going away. The merge is how every configured install resolves its rules: a user's file is laid over the shipped one with a union that is left-biased per pattern and per property.
Precedence and combining two rulesets are properties of RuleSet, not of the formatter; the formatter was only the instrument they were observed through. Adds the two that were missing: a prefix key reaches below the node it names, and length settles before specificity. matchModeSpec now builds its rules from JBFL source too, so nothing here constructs a RuleSet by hand.
webdevred
force-pushed
the
rule-lookup-trie
branch
from
August 16, 2026 15:28
d3cd613 to
c299d8f
Compare
webdevred
force-pushed
the
rule-lookup-trie
branch
2 times, most recently
from
August 16, 2026 16:51
1e04c2f to
2a9c631
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Groundwork for #187. This branch will hold the rule lookup rewrite, and starts with the tests that have to hold through it.
Two things the rewrite must preserve had nothing checking them.
How a pattern matches a cursor.
sameBywalks both sequences and then decides on its last line: the pattern must be consumed whole, and leftover breadcrumbs are allowed underPrefixMatchalone. A trie descends one selector at a time and has to answer the same way, in particular by not answering early. Four specs cover equal length, a shorter pattern as a prefix, a pattern longer than the cursor, and keepingAnyObjectKeyandAnyArrayIndexapart.Which mode each property is read in.
doFormatNodehardcodes it:AutoPad,AlignObjectKeysandAutoPadSubObjectscome from an exact match,ComplexNewLineandTrailingCommafrom a prefix match. ReadingAutoPadfrom the prefix set instead leaves the whole fixture suite green, so nothing was guarding it. Two specs now do. They pin the split as it stands before>, which is meant to replace it, and the comment says so.Every spec was checked by mutating the source rather than the test, one mutation at a time, and each one reddens only the spec that claims it.
.test*gets its own spec in the same group. It is documented inJBFL_DOCS.mdand ships with the package, so the trie has to solve it rather than choose whether to keep it, and it is the one selector that cannot be keyed on directly: the stored key is a prefix of the breadcrumb rather than the same text. Either a character trie over the key text, or a scan of just that level's prefix patterns, which is a different thing from today's scan over every pattern at every node.